package com.aikg.kgrag_java.service.impl;

import com.aikg.kgrag_java.utils.MinioUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aikg.kgrag_java.pojo.entity.Project;
import com.aikg.kgrag_java.service.ProjectService;
import com.aikg.kgrag_java.mapper.ProjectMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
* @description 针对表【project(项目信息表)】的数据库操作Service实现
* @createDate 2025-01-08 21:40:28
*/
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project>
    implements ProjectService{

    @Resource
    private MinioUtil minioUtil;

    @Resource
    private IndexServiceImpl indexServiceImpl;

    /**
     * 删除领域，删除领域下的所有知识库、文件、索引库
     * @param projectId
     * @return
     */
    @Override
    public boolean deleteProject(Integer projectId) {
        if (projectId == null){
            return false;
        }
//         删除mysql
        boolean mysql = this.removeById(projectId);
        if (!mysql){
            log.error("删除mysql领域失败");
            return false;
        }

        String projectStr = "" + projectId;

        // 删除minio文件
        boolean minio = minioUtil.deleteAllFilesByBucketName(projectStr);
        if(!minio){
            log.error("删除minio文件失败");
            return false;
        }

        // 删除索引库
        boolean project_id = indexServiceImpl.deleteByQuery(projectStr, "project_id", projectStr);
        if (!project_id){
            log.error("删除索引库失败");
            return false;
        }

        // 删除neo4j节点

        return true;
    }
}




